package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class 数位排序 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=1000010;
       static int a[]=new int[N],tmp[]=new int[N],n,m;
       
       static void swap(int i,int j){
    	      int t=a[i];
    	      a[i]=a[j];
    	      a[j]=t;
       }
       static int comp(int ai,int x){
    	      int t1=0;
    	      while(ai>0){
    	    	  t1+=ai%10;
    	    	  ai/=10;
    	      }
    	      int t2=0;
    	      while(x>0){
    	    	  t2+=x%10;
    	    	  x/=10;
    	      }
    	      return t1-t2;
       }
       	      
       static void merge_sort(int l,int r){
    	      if(l>=r)return;
    	      int mid=l+r>>1;
    	      merge_sort(l, mid);
    	      merge_sort(mid+1, r);
    	      int k=0,i=l,j=mid+1;
    	      while(i<=mid&&j<=r){
    	    	    if(comp(a[i],a[j])<=0)
    	    	    	tmp[k++]=a[i++];
    	    	    else tmp[k++]=a[j++];
    	      }
    	      while(i<=mid)
    	    	   tmp[k++]=a[i++];
    	      while(j<=r)
    	    	   tmp[k++]=a[j++];
    	      for(i=l,j=0;i<=r;i++,j++)
    	    	  a[i]=tmp[j];
       }
       public static void main(String[] args) throws  IOException {
		      n=Integer.parseInt(br.readLine());
		      m=Integer.parseInt(br.readLine());
		      for(int i=1;i<=n;i++){
		    	  a[i]=i;
		      }
		    	 
		      merge_sort(1,n);
		      System.out.print(a[m]);
		      
	}
}

